package com.song.JavaThread_day04.ch4_11;

import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class ReportProcessor implements Runnable {
	
	
	private CompletionService<String> service;
	
	private boolean end;
	
	public ReportProcessor(CompletionService<String> service) {
		super();
		this.service = service;
	}



	@Override
	public void run() {
		while(!end){
			try {
				Future<String> result = service.poll(20 , TimeUnit.SECONDS);
				if(result !=null)
				{
					String report = result.get();
					System.out.printf(" Report Receiver :Report Received %s \n",report);
				}
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ExecutionException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.out.printf("Report Sender :End \n");
	}
	
	public void setEnd(boolean end)
	{
		this.end = end;
	}
}
